<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>editor</title>
		<script type="text/javascript" src="../js/ewa.min.js"></script>
		<script type="text/javascript" src="htmlformat.js"></script>
		<style type="text/css">
.but div {
	overflow: hidden;
	width: 16px;
	height: 16px;
	margin: 3px;
	background-repeat: no-repeat;
	float: left;
	cursor: pointer;
	filter: alpha(opacity =                   70);
	opacity: 0.70;
	background-color: #FFF;
}

.but img {
	position: relative;
}
</style>
		<script type="text/javascript">
var lastFocus;
function mOver(evt) {
	var e = evt ? evt : window.event;
	var o = e.srcElement ? e.srcElement : e.target;
	if (o.tagName != 'IMG') {
		return;
	}
	if (lastFocus != null) {
		lastFocus.style.filter = 'alpha(opacity=70)';
		lastFocus.style.opacity = 0.7;
	}
	var o1 = o.parentNode;
	o1.style.filter = 'alpha(opacity=100)';
	o1.style.opacity = 1;
	lastFocus = o1;
}
var fullWindow;
function mDown(evt) {
	var e = evt ? evt : window.event;
	var o = e.srcElement ? e.srcElement : e.target;

	if (o.tagName != 'IMG') {
		return;
	}
	var o1 = o.parentNode;
	if (o1.id == 'FULL') {
		var u = window.frames[0].location.href + '?f=1';
		var width = document.body.offsetWidth;
		var height = document.body.offsetHeight;

		fullWindow = window.parent.EWA.UI.Dialog.OpenWindow(u, 'edit', width,
				height, false);

	} else if (o1.id == 'CODE_TXT') {
		var tag = o1.getAttribute('tag');
		if (tag == 'html') {
			var html = style_html(window.frames[0].document.body.innerHTML, 4,
					' ', 80);
			document.getElementById('txt').style.display = '';
			document.getElementById('f1').style.display = 'none';
			o1.setAttribute('tag', 'txt');
			if (window.frames[1].editor) {
				window.frames[1].editor.setValue(html);
			} else {
				__VAL__ = html;
				__TYPE__ = 'html';

				window.frames[1].initEditor();
			}
		} else {
			document.getElementById('txt').style.display = 'none';
			document.getElementById('f1').style.display = '';
			o1.setAttribute('tag', 'html');
			window.frames[0].document.body.innerHTML = window.frames[1]
					.getText();
		}
	}else if(o1.id=="PLAIN_TEXT"){
		var btn=window.top.EWA.LANG=="enus"?"Paste Plain Text":"粘贴纯文本";
		var dia=window.parent.$DialogHtml("<textarea style='width:100%;height:160px'></textarea>"
			+"<input style='float:right;margin:3px;' type='button' value='"+btn+"'>");
		var c=dia.getContent();
		c.getElementsByTagName("input")[0].onclick=function(){
			var t=c.getElementsByTagName("textarea")[0].value;
	        var t2=t.split("\n");
	        var t3="<div>"+t2.join("</div><div>")+"</div>";
	        if(t.length>0){
	        	window.frames[0].document.body.innerHTML=t3;
	        }
			dia.Close();
		}		
	} else if (o1.id == 'IMG') {
		insertImg(window);
	} else {
		if (o1.id == 'CreateLink') {
			window.frames[0].document.execCommand(o1.id, true, null);
		} else {
			window.frames[0].document.execCommand(o1.id, false, null);
		}
		window.frames[0].document.body.focus();
	}
}
function changeForColor(o) {
	window.frames[0].document.execCommand('ForeColor', false, o.value);
}
function insertImg(win) {
	var retCmd = new window.parent.EWA.UI.Dialog.CMD();
	retCmd.CmdArgus[0] = win;
	retCmd.CmdArgus[1] = "DHTML";
	retCmd.CmdArgus[2] = window.parent.EWA.CP;
	retCmd.CmdArgus[3] = window.parent.EWA.B.IE ? window.frames[0].document.selection
			.createRange()
			: null;

	var url = '../cgi-bin/_up_/?EWA_UP_TYPE=IMAGE'
	window.parent.EWA.UI.Dialog.OpenWindow(url, 'loadimg', 420, 300, false,
			null, retCmd);
}
function onload1() {
	var iframes = window.parent.document.getElementsByTagName('iframe');
	for ( var i = 0; i < iframes.length; i++) {
		var o = iframes[i];
		if (o.contentWindow == window) {
			fromObj = o.parentNode.getElementsByTagName('input')[0];
			var s= fromObj.value.replace(/\<script/ig,"[脚本").replace(/\<\/script/ig,"[脚本");
			window.frames[0].document.body.innerHTML = s;
		}
	}
	var win = window.frames[0];
	var doc = win.document;

	if (document.all) {
		doc.body.contentEditable = true;
	} else {
		doc.designMode = 'on';
	}

	doc.body.onblur = function() {
		fromObj.value = this.document.body.innerHTML;
	}
}
function loadImages(data) {
	var d = eval(data);
	var t = window.parent.document.getElementById('UP_IMG_' + fromName);
	for ( var i = 0; i < d.length; i++) {
		createImg(d[i]);
		if (t.value.length > 0) {
			t.value += ',';
		}
		t.value += d[i]["UP_UNID"];
	}
}
function createImg(d) {
	var img = document.createElement("img");
	img.src = EWA.CP + "/" + d["UP_URL"];
	img.width = 50;
	img.height = 38;
	img.title = d["UP_NAME"];
	img.style.cursor = 'pointer';
	img.onclick = function() {
		var doc = window.frames[0].document;
		var m = doc.createElement('img');
		m.src = this.src;
		doc.body.appendChild(m);
		m.style.margin = '2px';
	}

	var span = document.createElement("span");
	span.style.marginTop = '2px';
	span.style.border = '1px solid gray';
	span.style.backgroundColor = '#fff';
	span.style.padding = '2px';
	span.appendChild(img);

	document.getElementById('imgs').childNodes[0].appendChild(span);
}
</script>
	</head>
	<body style='margin: 0px; overflow: hidden' onload='onload1()'>
		<table width="100%" height=100% border=0 cellspacing=0 cellpadding=0>
			<tr>
				<td height=25 style='border-right: 1px solid #ccc'>
					<div class=but onmouseover="mOver(event)"
						onmousedown="mDown(event)">
						<div id='BOLD'>
							<IMG style="TOP: -304px" src="i.gif">
						</div>
						<div id='ITALIC'>
							<IMG style="TOP: -320px" src="i.gif">
						</div>
						<div id='UNDERLINE'>
							<IMG style="TOP: -336px" src="i.gif">
						</div>
						<div id='InsertOrderedList'>
							<IMG style="TOP: -400px" src="i.gif">
						</div>
						<div id='InsertunOrderedList'>
							<IMG style="TOP: -416px" src="i.gif">
						</div>
						<div id='INDENT'>
							<IMG style="TOP: -448px" src="i.gif">
						</div>

						<div id='Outdent'>
							<IMG style="TOP: -432px" src="i.gif">
						</div>

						<div id='JustifyLEFT'>
							<IMG style="TOP: -464px" src="i.gif">
						</div>
						<div id='JustifyCENTER'>
							<IMG style="TOP: -480px" src="i.gif">
						</div>
						<div id='JustifyRIGHT'>
							<IMG style="TOP: -496px" src="i.gif">
						</div>
						<div id='CreateLink'>
							<IMG style="TOP: -526px" src="i.gif">
						</div>
						<div id='ForeColor' style='width: 30px;'>
							<select onchange='changeForColor(this)'>
								<option value='' style=''>
								</option>

								<option value='black' style='background-color: black'>
									黑色
								</option>
								<option value='red' style='background-color: red'>
									红色
								</option>
								<option value='blue' style='background-color: blue'>
									蓝色
								</option>
								<option value='green' style='background-color: green'>
									绿色
								</option>
								<option value='yellow' style='background-color: yellow'>
									黄色
								</option>
							</select>
						</div>

						<div id='CODE_TXT' tag='html'>
							<IMG style="TOP: -80px" src="i.gif">
						</div>
						<div id='PLAIN_TEXT'>
							<IMG style="TOP: -144px" src="i.gif">
						</div>
					</div>
				</td>
			</tr>

			<tr>
				<td style='border: 1px solid #ccc'>
					<iframe id='f1' width=100% height=100% frameborder=0
						src="about:blank"></iframe>
					<iframe id='txt' src='CodeMirror/index.html'
						style='display: none; width: 100%; height: 100%' frameborder=0></iframe>
				</td>
			</tr>
		</table>

	</body>
</html>